<template>
	<view class="myhelp row">
		<view v-if="dataList.length">
			<view class="list" v-for="item in dataList" :key="item.id" @click="fillIn(item)">
				<image class="img" :src=" item.url || '../../static/noPictures.jpg'" mode=""></image>
				<view class="content">
					<text class="c_title">{{ item.diseaseName || '暂无该疾病' }}</text>
					<template>
						<text class="c_state" v-if="item.status == 0">待回复</text>
						<text class="c_state" v-if="item.status == 10">已答复</text>
					</template>
				</view>
				<view class="btn">
					<van-button class="button" type="default">详情</van-button>
				</view>
			</view>
		</view>
		<view v-else class="noData">
			<image src="../../static/noData.png"></image>
			<view class="text">暂无数据</view>
		</view>
		<view class="loading" v-show="isShowMore">没有更多数据了~</view>
		<van-toast id='van-toast'/>
	</view>
</template>

<script>
	import { getOwnList, seekHelpList } from '@/api/my'
	import { fileById } from '@/api/common'
	export default {
		name: 'myhelp',
		data() {
			return {
				initialList: [],
				pagination: {
					pageSize: 10,
					pageNum: 1,
					
				},
				total: 0
			}
		},
		onShow() {
			this.getList()
		},
		onPullDownRefresh() {
			this.pagination.pageNum = 1;
			setTimeout(() => {
				this.getList();
			}, 200)
			setTimeout(() => {
				uni.stopPullDownRefresh();
			}, 1300);
		},
		onReachBottom() {
			if ((this.pagination.pageSize * this.pagination.pageNum) >= this.total) {
				return
			}
			this.pagination.pageNum ++;
			this.getList('more')
		},
		computed: {
			dataList() {
				let diseaseList = this.$storage.getItem('diseaseList');
				if (this.initialList && diseaseList) {
					this.initialList.map(item => {
						diseaseList.map(el => {
							if (item.diseaseId == el.id) {
								this.$set(item, 'diseaseName', el.name)
							}
						})
					})
					return this.initialList
				}
			},
			isShowMore() {
				if ((this.pagination.pageSize * this.pagination.pageNum) >= this.total && this.total!=0) {
					return true
				} else {
					return false
				}
			}
		},
		methods: {
			getList(mode) {
				getOwnList({...this.pagination}).then(res => { 
					if (mode == 'more') {
						this.initialList = this.dataList.concat(res.data.rows);
					} else {
						this.initialList = res.data.rows;
					}
					this.initialList.map(item => {
						if (item.imgTheme) {
							fileById({ fileId: item.imgTheme }).then(res => {
								this.$set(item,'url', res.data.accessUrl);
							})
						}
					})
					this.total = res.data.total;
				})
			},
			fillIn(val) {
				uni.navigateTo({
					url: `./detail?id=${val.id}&diseaseName=${val.diseaseName}`
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.myhelp {
		width: 100%;
		position: relative;
		min-height: 100vh;
		background-color: #F5F5F5;
		padding-top: 1rpx;
		.list {
			display: flex;
			margin-top: 20rpx;
			padding: 30rpx;
			background-color: #ffff;
			.img {
				width: 180rpx;
				height: 180rpx;
				border-radius: 20rpx;
			}
			.content {
				display: flex;
				width: calc(100% - 180rpx - 100rpx - 20rpx - 48rpx);
				margin-left: 20rpx;
				margin-right: 40rpx;
				flex-direction: column;
				justify-content: space-between;
				.c_title {
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
					font-size: 36rpx;
				}
				.c_cont {
					overflow: hidden;
					white-space: nowrap;
					text-overflow: ellipsis;
					font-size: 30rpx;
				}
			}
			.btn {
				width: 100rpx;
				position: relative;
				.button {
					width: 100rpx;
					height: 60rpx;
					position: absolute;
					bottom: 0;
					right: 0;
					font-size: 20rpx;
					border: 1px solid #BCEFCD;
					/deep/ .van-button--normal {
						width: 100%;
						height: 100%;
						padding: 0 0;
					}
				}
			}
		}
	}
</style>
